<template>
  <views>
    <div class="system_config">
      <viewTitle  :title="'系统设置'"></viewTitle>
        <el-tabs v-model="activeName" @tab-click="getData(activeName)" class="system_config_content">
          <el-tab-pane v-for="item in channel_list" :key="item.id" :label="item.value" :name="item.id">
            <el-form ref="form" label-width="auto">
              <el-form-item v-for="vo in configs" :label="vo.config_name">
                <el-input type="text" clearable :placeholder="'请输入'+vo.config_name" v-model="vo.config_value" ></el-input>
              </el-form-item>
            </el-form>
          </el-tab-pane>
        </el-tabs>
        <el-button type="primary" @click="save" class="save-btn">保存</el-button>
    </div>
  </views>
</template>

<script>
export default {
  data() {
    return {
      configs:{},
      channel_list : [],
      activeName: ''
    };
  },
  created() {
      let { code, msg, data } = this.$api.sendSync(
          this.$mapapi.admin_getAllChannel
      )
      if (code != 200) {
          return;
      }
      this.channel_list = data
      this.activeName = this.channel_list[0].id;
  },
  mounted() {
      this.getData()
  },
  computed:{
    save_data(){
        let data = {};
        data.configs = this.configs
        return data;
    }
  },
  methods: {

    //   修改
    save(){
         this.$raxios.post(
            this.$mapapi.admin_setConfig,{data:this.save_data}
        ).then(res=>{
          if(res.code==200){
            this.$message({type: "success", message: "保存成功!"});
          }else{
	          this.$message.error(res.msg)
             return;
          }
        })
        // this.configs = data
    },
    //   获取数据
    getData() {
       let post_data={
        channel:this.activeName
       }
         this.$raxios.post(
            this.$mapapi.admin_getChannelConfig,{data:post_data}
        ).then(res=>{
          if(res.code==200){
           this.configs = res.data
          }else{
	          this.$message.error(res.msg)
              return
          }
        })
    }
  }

};
</script>
<style lang="less"  scope="true"   src="@/style/system_manager/system_config.less">
</style>
